package com.tianyu.jty.collector.service.extractor;

import com.tianyu.jty.collector.entity.Site;
import com.tianyu.jty.collector.service.outputs.AbstractOutput;
import com.tianyu.jty.collector.utils.HttpClientUtil;

import java.util.List;

/**
 * Created by xtao on 2015/11/8.
 */
public class JsonExtractor extends Extractor {

    private List<String> keys;

    public JsonExtractor() {
    }

    public JsonExtractor(Site site, AbstractOutput output) {
        super(site);
        this.outputers.add(output);
        this.keys = site.getJsonKeys();
    }

    @Override
    public void extract() throws Exception {
        String jsonStr = getJsonString();

        for(String key: keys){
            String content = "";
            site.getResult().put(key, jsonStr);
        }
    }



    private String getJsonString(){
        HttpClientUtil httpClientUtil = HttpClientUtil.getInctence();
        return httpClientUtil.doGet(site.getUrl());
    }


}
